from django import template

register = template.Library()


def fmt_uname(value, count):
    '''
    格式化用户昵称
    :param count: 显示前几个字
    :param value:
    :return:
    '''
    if len(value) < count:
        name = value
    else:
        name = value[:count]

    if (len(value) - count) <= 0:
        name_sign = '{}'.format(value)
    elif (len(value) - count) == 1:
        name_sign = '{}*'.format(value[:count])
    else:
        name_sign = '{}**'.format(value[:count])
    return name_sign


register.filter('fmt_uname', fmt_uname)